<?php
/*
 * 竞猜格式检测
 * */
function check_format($message) {
	$data['error'] = 1;
	//车号大小单双(20-20,000)
	// 12345/双/100 = 1~5车道买双各$100 = 总$500
	if (preg_match('/^(?!\d*?(\d)\d*?\1)\d{1,10}+\/{1}+(大|双|小|单){1}+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		if($info[2]>=20 && $info[2]<=20000){
			$data['start'] = serialize(str_split($info[0]));
			$data['points'] = $info[2]*strlen($info[0]);
			$data['type'] = 1;
		}else{
			$data['error'] = 0;
			$data['money'] = '20-20,000';
		}
	}

	//车号(20-20,000)
	// 12345/89/20 = 1~5车道的8号、9号各买$20 = 总$200
	if (preg_match('/^(?!\d*?(\d)\d*?\1)\d{1,10}+\/{1}+(?!\d*?(\d)\d*?\1)\d{1,10}+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		if($info[2]>=20 && $info[2]<=20000){
			$data['start'] = serialize(str_split($info[0]));
			$data['points'] = $info[2]*strlen($info[0])*strlen($info[1]);
			$data['type'] = 2;
		}else{
			$data['error'] = 0;
			$data['money'] = '20-20,000';
		}
	}

	//组合(20-10,000)
	// 890/大单/50 = 8.9.10车道大单各买$50 = 总$150
	if (preg_match('/^(?!\d*?(\d)\d*?\1)\d{1,10}+\/{1}+(大单|小双|小单|大双){1}+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		if($info[2]>=20 && $info[2]<=10000){
			$data['start'] = serialize(str_split($info[0]));
			$data['points'] = $info[2]*strlen($info[0]);
			$data['type'] = 3;
		}else{
			$data['error'] = 0;
			$data['money'] = '20-10,000';
		}
	}

	//龙虎(20-20,000)
	// 123/龙/100 = 1~3车道买龙各$100=总$300
	if (preg_match('/^(?![1-5]*?([1-5])[1-5]*?\1)[1-5]{1,5}+\/{1}+(龙|虎){1}+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		if($info[2]>=20 && $info[2]<=20000){
			$data['start'] = serialize(str_split($info[0]));
			$data['points'] = $info[2]*strlen($info[0]);
			$data['type'] = 4;
		}else{
			$data['error'] = 0;
			$data['money'] = '20-20,000';
		}
	}

	//冠亚庄闲(20-20,000)
	// 庄/200 = 冠军大于亚军即中奖
	if (preg_match('/^(庄|闲){1}+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		if($info[1]>=20 && $info[1]<=20000){
			$data['start'] = serialize(str_split($info[0]));
			$data['points'] = $info[1];
			$data['type'] = 5;
		}else{
			$data['error'] = 0;
			$data['money'] = '20-20,000';
		}
	}

	//冠亚号码(20-5,000)
	// 组/5-6/50 = 5号.6号车在冠亚军(顺序不限) = 总$50
	// 组/1-9.3-7/100 = 1.9号车或3.7号车在冠亚军(顺序不限) = 总$200
	if (preg_match('/^组\/{1}+([0-9]{1}-[0-9]{1}.)*([0-9]{1}-[0-9]{1})+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		if($info[2]>=20 && $info[2]<=5000){
			if (strlen($info[1]) > 3) {
				$info2 = explode('.', $info[1]);
				for ($i = 0; $i < count($info2); $i++) {
					$info3[$i] = explode('-', $info2[$i]);
					if ($info3[$i][0] == $info3[$i][1]) {
						$res = 0;
						return false;
					} else {
						$res = 1;
					}
					for ($a = 0; $a < $i - 1; $a++) {
						if ($info2[$i] == $info2[$a]) {
							$res = 0;
							return false;
						} else {
							$res = 1;
						}
						$info3 = explode('-', $info2[$a]);
						$info4 = $info3[1] . '-' . $info3[0];
						if ($info2[$i] == $info4) {
							$res = 0;
							return false;
						} else {
							$res = 1;
						}
					}
				}
				if ($res == 1) {
					$data['start'] = serialize($info2);
					$data['points'] = $info[2]*count($info2);
					$data['type'] = 6;
				}
			} else {
				$info1 = explode('-', $info[1]);
				if ($info1[0] != $info1[1]) {
					$data['start'] = serialize(array('0' => $info[1]));
					$data['points'] = $info[2];
					$data['type'] = 6;
				}
			}
		}else{
			$data['error'] = 0;
			$data['money'] = '20-5,000';
		}	
	}

	//特码大小单双(20-20,000)
	// 和双100 = 「冠亚和」的双$100
	if (preg_match('/^(和|特){1}(大|小|单|双){1}+\d+$/', $message)) {
		$info = substr($message, 6);
		if($info>=20 && $info<=20000){
			$data['start'] = serialize(str_split($info[0]));
			$data['points'] = $info;
			$data['type'] = 7;
		}else{
			$data['error'] = 0;
			$data['money'] = '20-20,000';
		}
	}

	//特码数字
	// 3.4.18.19，含本42倍，限额20-1,000
	// 5.6.16.17，含本21倍，限额20-2,000
	// 7.8.14.15，含本14倍，限额20-3,000
	// 9.10.12.13，含本10倍，限额20-4,000
	// 11，含本8倍，限额20-5,000
	// 和5.6.7/100 = 竞猜「冠亚和」的值为5或6或7各$100 = 总$300
	if (preg_match('/^(和|特){1}(([3-9]|1[0-9]).)*([3-9]|1[0-9])+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		$start = substr($info[0], 3);
		if($info[1]>=20){
			if (strlen($start) > 1) {
				$res = explode('.', $start);
				if (count($res) == count(array_unique($res))) {
					$data['start'] = serialize(str_split(substr($info[0], 3)));
					$data['points'] = $info[1]*count($res);
					$data['type'] = 8;
				}
			} else {
				$data['start'] = serialize(str_split(substr($info[0], 3)));
				$data['points'] = $info[1];
				$data['type'] = 8;
			}
		}else{
			$data['error'] = 0;
			$data['money'] = '20-5,000';
		}
	}

	//特码区段(20-10,000)
	//BC/100 = 投注BC段位各100＝总$200
	if (preg_match('/^(A|B|C){1,4}+\/{1}+\d+$/', $message)) {
		$info = explode('/', $message);
		if($info[1]>=20 && $info[1]<=10000){
			$data['start'] = serialize(str_split($info[0]));
			$data['points'] = $info[1]*count(str_split($info[0]));
			$data['type'] = 9;
		}else{
			$data['error'] = 0;
			$data['money'] = '20-10,000';
		}
	}
	return $data;
}
?>